<?php
/**
 * @name SamplePlugin
 * @desc Yaf定义了如下的6个Hook,插件之间的执行顺序是先进先Call
 * @see http://www.php.net/manual/en/class.yaf-plugin-abstract.php
 * @author 
 */
class TwigPlugin extends Yaf\Plugin_Abstract {

	public function routerStartup(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response) {
	}

	public function routerShutdown(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response) {

        $config = \Yaf\Registry::get('config')->toArray();
        $dispatcher= Yaf\Dispatcher::getInstance();
        $twig = '';
        // view 放在module 目录里
        if($request->module==$config['application']['dispatcher']['defaultModule']){
            $twig = new \TwigAdapter(APP_PATH.'views', $config['twig']);
        } else {
            $twig = new \TwigAdapter(APP_PATH.'modules/'.$request->module.'/views', $config['twig']);
        }
        $dispatcher->setView($twig);
	}

	public function dispatchLoopStartup(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response) {
	}

	public function preDispatch(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response) {
	}

	public function postDispatch(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response) {
	}

	public function dispatchLoopShutdown(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response) {
	}
}
